//
//  UIColor+Web.m
//  Car4S
//
//  Created by mini on 13-4-16.
//
//

#import "UIColor+Web.h"

@implementation UIColor (Web)
+ (UIColor *)colorWithHexString:(NSString *)hex
{
    NSRange range = [hex rangeOfString:@"#"];
    NSString *str = hex;
    NSInteger step = 2;
    unsigned int r, g, b, alpha;
    if (range.location != NSNotFound) {
        str = [str substringFromIndex:range.location + 1];}
    if (str.length < 8) {
        str = [str stringByAppendingString:@"ffffffff"];
    }
    NSScanner *scanner = [NSScanner scannerWithString:[str substringWithRange:NSMakeRange(0, step)]];
    [scanner scanHexInt:&r];
    scanner = [NSScanner scannerWithString:[str substringWithRange:NSMakeRange(0 + step, step)]];
    [scanner scanHexInt:&g];
    scanner = [NSScanner scannerWithString:[str substringWithRange:NSMakeRange(0 + 2 * step, step)]];
    [scanner scanHexInt:&b];
    scanner = [NSScanner scannerWithString:[str substringWithRange:NSMakeRange(0 + 3 * step, step)]];
    [scanner scanHexInt:&alpha];
    return [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:alpha/255.0];
}
@end
